package com.leetcode.shuzu;

import java.util.Arrays;

//[[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
public class RotateTest2 {
    public static void main(String[] args) {
        int[][] arr = {{5,1,9,11},{2,4,8,10},{13,3,6,7},{15,14,12,16}};
        int[][] rotate = rotate(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(Arrays.toString(arr[i]));
        }
    }

    private static int[][] rotate(int[][] arr) {
        for (int i = 0; i < arr.length/2; i++) {
            for (int j = 0; j <arr[i].length ; j++) {
                int temp = arr[i][j];
                arr[i][j] = arr[arr.length-i-1][j];
                arr[arr.length-i-1][j] = temp;
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.println(Arrays.toString(arr[i]));
        }
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < i; j++) {
                int temp = arr[i][j];
                arr[i][j] = arr[j][i];
                arr[j][i] = temp;
            }
        }
        return arr;
    }
}
